package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper mapper;

    @Override
    public EmployeeBean login(String name, String pwd) {
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();
        qw.eq("e_name", name);
        qw.eq("e_pwd", pwd);
        return mapper.selectOne(qw);
    }

    @Override
    public IPage<EmployeeBean> cutByItem(Integer pageN0, String name, String dept) {
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();
        if (name != null) {
            qw.like("e_name", name);
        }
        if (dept != null) {
            qw.like("e_dept", dept);
        }
        return mapper.selectPage(new Page<>(pageN0, 3), qw);
    }

    @Override
    public List<EmployeeBean> findByIds(Integer[] idArray) {
        List<EmployeeBean> emList = new ArrayList<>();
        for (int i = 0; i < idArray.length; i++) {
            EmployeeBean em = mapper.selectById(idArray[i]);
            emList.add(em);
        }
        return emList;
    }
}
